<?php
declare (strict_types=1);

namespace app\course\model\video;

use app\course\model\base\Course as BaseCourse;

/**
 * 点播课程
 */
class Video extends BaseCourse
{
    public function getDeleteTimeAttr($value): int
    {
        return $value ?: 0;
    }

    /**
     * 全局查询范围
     *
     * @var [type]
     */
    protected $globalScope = ['courseType'];

    /**
     * 定义查询设备类型范围条件
     * Author   Martinsun<syh@sunyonghong.com>
     * Date 2020-03-10
     *
     * @param    [type]                         $query [description]
     * @return void [type]                                [description]
     */
    public function scopeCourseType($query)
    {
        $query->partition('p1');
    }

    /**
     * 搜索器 - ID
     * Author   亓官雨树<lucky.max@foxmail.com>
     * Date 2020-03-16
     */
    public function searchIdAttr($query, $value, $data)
    {
        $query->where('id', $value);
    }

    /**
     * 搜索器 - 标题title
     * Author   亓官雨树<lucky.max@foxmail.com>
     * Date 2020-03-16
     */
    public function searchtitleAttr($query, $value, $data)
    {
        $query->where('title', 'LIKE', '%' . $value . '%');
    }

    /**
     * 搜索器 - 课程类型【1:点播 2:直播 3:面授 4:班级】
     * Author   亓官雨树<lucky.max@foxmail.com>
     * Date 2020-03-16
     */
    public function searchCourseTypeAttr($query, $value, $data)
    {
        $query->where('course_type', $value);
    }

    /**
     * 搜索器 - 课程分类
     * Author   亓官雨树<lucky.max@foxmail.com>
     * Date 2020-03-16
     */
    public function searchCategoryAttr($query, $value, $data)
    {
        $query->where('fullcategorypath', 'LIKE', '%,' . $value . ',%');
    }

}
